Humble CAD Viewer

Squeezing Yet Another Application From

The Two Functions, ScreenX() and ScreenY()

by Tomas J. Nally

Steelweaver52@aol.com


Home

TCP/IP Tutorial

Rich Text Format Help

Creating Graphics for Games

Automatic Menu

Humble CAD Viewer

Demo: Aligning Numbers

Thoughts On Cross-Platform Help

Submission Guildlines

Newsletter Help

Index

Enough Already!

Way back in Issue 113 of the Liberty BASIC Newsletter, I was pleased to provide an article called Easy Functions For Plotting 3D Objects. This article discussed two functions I wrote, ScreenX() and ScreenY(), which allowed programmers to easily plot three-dimensional wire model images.

In Issue 114 of the newsletter, I followed that up with an article called View3D - A Mini-Application Written to Showcase ScreenX() and ScreenY(). View3d relied on ScreenX() and ScreenY() to produce 3D images, but the program also provided a set of mouse-controlled sliders to quickly move the camera around the 3D model, and to zoom-in and zoom-out from the model.

Because hard-headedness is one of my finer assets, I'm providing yet one more application using ScreenX() and ScreenY(): Humble CAD Viewer.

What Is Humble CAD Viewer (HCV)?

Screen Shot of Humble CAD Viewer

Humble CAD Viewer is a program for viewing the data files (*.hcd) and object files (*.hco) created with Humble CAD. These files contain the "node" and line data required to produce images of three-dimensional objects. Humble CAD is a Liberty BASIC program authored by me that allows the easy creation of 3D images. Version 1.5.1 of Humble CAD was released in early 2003.

The images that Humble CAD produces show objects whose surfaces are transparent. The edges of the objects, however, are rendered as lines. For this reason, these images are often characterized as "wire model images". A Humble CAD cube will actually look like a wire model of a cube.

Naturally, Humble CAD itself can be used to view the images which it has created. However, the Humble CAD Viewer, by relying on the sliders developed for View3D, makes changing the view of a Humble CAD object so much easier and more fun.

Understand that Humble CAD Viewer can only view Humble CAD data files; it cannot create and edit them. For that you need the regular Humble CAD program.

What Files Will HCV Open?

The regular Humble CAD application produces two types of files: Humble CAD data files (*.hcd) and Humble CAD object files (*.hco). The *.hcd format was constructed to hold the data for multiple Humble CAD 3D objects. The *.hco format was constructed to hold data for a single 3D object. HCV will open both of these file types.

To open a Humble CAD data file with HCV, from the File menu select "Open Humble CAD Data File (*.hcd)...". From the File Open dialog box, select one of the *.hcd files provided with HCV. Or, if you have Humble CAD installed, you may navigate to an *.hcd file stored in the Humble CAD \data folder. Opening a Humble CAD Object File is a near identical procedure, except that files with the *.hco extension are selected from the File Dialog window.

Working The HVC Viewing Controls

X + Z Camera Control

One helpful point to remember when working the HCV controls is this: controls are not activated by holding down the left button and dragging the mouse. Rather, controls are activated by left-clicking once, and releasing the left mouse button, then moving the mouse pointer. The control will move with the mouse pointer until the control is "released" by a single right click of the mouse. This applies to all three slider controls.

Below is a mini-tutorial for operating the HCV controls:

Setting the View Control "Extents"

X + Z Camera Contol Extents dialog

Though HCV relies heavily on the sliders first written for View3D, HVC provides several new features, too. Primarily, these features allow control of the viewing extents.

The view extents refers to the size of the arena within which the camera can be placed. This is an important issue for the following reason. Say that you have an object that is 10 units wide. It might be useful to move the camera 100 units away from the object to view it, so it would be nice for the camera's viewing arena to be about 250 units wide. By the same token, it probably wouldn't be useful to move the camera 10,000 units away from a 10 unit object because the object would be too small. By setting the viewing extents, you establish a conviently-sized viewing arena within which you can move the camera.

The view extents can be set for both the X + Z Camera Control and the Y Camera Control. To set the X + Z Camera Control extents, do the following:

  1. From the HCV menu, select "View-Controls" and then "X + Z Camera Control Extents...". A new dialog box will appear. Near the bottom of the dialog box, there will be a combo box which provides a number of extents ranges from which to choose. The ranges offered vary from 100 by 100 to 10,000 by 10,000.

  2. Using the combo box, select the viewing extents range that is best suited for the size of the objects in the viewing window.

  3. After you've made your selection, click the "OK" button, which applies the new extents and closes the window. If you decide not to change the extents, then click the "Cancel" button.

Setting the Y Camera Control extents is very similar. From the HCV menu, select "View-Controls" and then "Y Camera Control Extents...". After that, follow the steps identified above for setting the "X + Z Camera Control Extents".

Setting the Viewing Center and the Screen Center

Viewing Center and Screen Center dialogs

The Viewing Center is that point in space where you are pointing the Camera. The Screen Center is that point in the Liberty BASIC GRAPHICBOX which corresponds to the Viewing Center. Humble CAD Viewer allows the user to set both of these points.

To select the Viewing Center,

  1. From the HCV menu, select "View-Controls" and then "Set Viewing Center...". A new dialog box will appear. The dialog box provides three TEXTBOXES within which you can input the coordinates of the Viewing Center. Alternatively, the dialog box provides a button which you can push to automatically set the Viewing Center to the geometric center of the objects.

  2. Select a new viewing center by either typing coordinates in the three TEXTBOXES, or pressing the button to set the viewing center automatically.

  3. Press "OK" to accept the new Viewing Center, or "Cancel" to keep the original viewing center.

Setting the Screen Center is a similar procedure.

  1. From the View-Controls menu, select "Set Screen Center...". A dialog box will appear. The dialog box will contain text instructions, as well as two TEXTBOXES and several buttons.

  2. To set the Screen Center to a new location in space, type in new values for X and Y in the two text boxes.

  3. If you would like the Screen Center set to the geometric center of the plot box, press the button "Set Screen Center to Plot Box Center". The program will assign the Screen Center to X = 200 and Y = 200, the default values at startup.

  4. Press the "OK" to accept the new Screen Center coordinates. Press the "Cancel" button to close the dialog box without changing the Screen Center.

One question you may ask is this: Why are there three coordinates for the Viewing Center, while the Screen Center requires only two coordinates? The reason is that the Viewing Center is a point in space. It is the location in space where you point the camera. The Screen Center is a point in the Plot Box, which is a Liberty BASIC GRAPHICBOX. All points in GRAPHICBOXes are defined by two coordinates only.

Possible Viewing Problems with Humble CAD Viewer

Hey, remember: this ain't AutoCad. Humble CAD and Humble CAD Viewer are extrusions from the mind of a hobbyist programmer, fueled by glazed donuts. Here are a few viewing problems that you may have, and ways to remedy them.

PROBLEM: Moving the camera location around the objects does not create a smooth viewing transition as claimed.

REMEDY: Sorry about that. Some Humble CAD files--particularly the Humble CAD data files--consist of hundreds of nodes and hundreds of lines. Every time the camera control moves even a single pixel, the entire 3D image needs to be redrawn. The two graphic routines, ScreenX() and ScreenY(), are easy to use (by design) but are not that efficient. The view transition is smoother with the fewer lines and nodes in the file, and with faster processors.

PROBLEM: After I read one of the help files, the objects in the plot box disappear.

REMEDY: Press the "Redraw" button near the bottom of the application window. This will replot all graphic objects, including the camera controls and the scale controls.

PROBLEM: All of the 3-D objects seem too big to be plotted in the main plot box.

REMEDY: There may be several ways to fix this. Try the following ways individually or in combination. (A) Move the blue box of the X + Z Camera Control farther away from the objects. (B) Set the Viewing Center to the Geometric Center of the objects. (C) Widen the X + Z Camera Control extents. (D) Increase the height of the Y Camera Control extents. (E) Zoom out from the objects using the Scale Control.

PROBLEM: All of the 3-D objects seem to plot too small.

REMEDY: This is the opposite to the problem described in (2). Try the following ways individually or in combination. (A) Move the X + Z Camera Control closer to the objects. (B) Set the Viewing Center to the Geometric Center of the objects. (C) Make the X + Z Camera Control extents smaller in magnitude. (D) Decrease the height of the Y Camera Control extents. (E) Zoom-in to the objects using the Scale Control.

PROBLEM: The objects don't appear in the X + Z Camera Control (or the Y Camera Control) regardless of how much I change the X + Z Camera Control extents or the Y Camera Control extents.

REMEDY: The Humble CAD Viewer works best if 3-D objects are within about 5,000 units of the origin in space. (The origin is defined as X = 0, Y = 0 and Z = 0.) If all of your 3-D objects are further away, they may not show up in the X + Z Camera Control, or the Y Camera Control. To change this situation, use the main Humble CAD program to change the location of your 3-D objects. Move them closer to the origin.

PROBLEM: After I minimize the program, the objects in the plot box disappear.

REMEDY: Essentially, this is the same problem as described in (1). Press the "Redraw" button near the bottom of the application window. This will replot all graphic objects, including the camera controls and the scale controls.

License

Humble CAD, Humble CAD Viewer, ScreenX() and ScreenY() are all released as open source.


Home

TCP/IP Tutorial

Rich Text Format Help

Creating Graphics for Games

Automatic Menu

Humble CAD Viewer

Demo: Aligning Numbers

Thoughts On Cross-Platform Help

Submission Guildlines

Newsletter Help

Index